home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / PLAYFILE.C < prev    next >
C/C++ Source or Header  |  1992-10-06  |  22KB  |  1,076 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   06 Oct 1992 15:15:50  $*/
  3. /*$Header:   X:/sccs/pcmapps/playfile.c_v   1.10   06 Oct 1992 15:15:50   DCODY  $*/
  4. /*$Log:   X:/sccs/pcmapps/playfile.c_v  $
  5.  * 
  6.  *    Rev 1.10   06 Oct 1992 15:15:50   DCODY
  7.  * No change.
  8.  * 
  9.  *    Rev 1.9   24 Sep 1992 08:59:20   DCODY
  10.  * changed MVGetHardware to mvGetHardware
  11.  * 
  12.  *    Rev 1.8   14 Sep 1992 17:22:38   SHAO_M
  13.  * Put all the text strings used in printf into playtext.h
  14.  * 
  15.  *    Rev 1.0   14 Sep 1992 17:01:30   unknown
  16.  * Initial revision.
  17.  * 
  18.  *    Rev 1.7   13 Aug 1992 08:26:18   DCODY
  19.  * corrected #if/#endif and } placement for TB stuff...
  20.  * 
  21.  *    Rev 1.6   04 Aug 1992 11:39:54   DCODY
  22.  * corrected t&l spelling
  23.  * 
  24.  *    Rev 1.5   28 Jul 1992 14:29:06   DCODY
  25.  * updated for Thunderboard and Thunder&Lightning
  26.  * 
  27.  *    Rev 1.4   20 Jul 1992 11:39:02   DCODY
  28.  * call to mvGetHWVersion now uses active I/O address detection.
  29.  * 
  30.  *    Rev 1.3   13 Jul 1992 18:54:14   DCODY
  31.  * removed initmvsound call
  32.  * 
  33.  *    Rev 1.2   01 Jul 1992 11:55:16   DCODY
  34.  * GaryL: Added OEM compiler flag checking for Welcome()
  35.  * to use the generic board name and to not display the MVI copyright.
  36.  * Note that the copyright is still present, as an imbedded static string.
  37.  * 
  38.  *    Rev 1.1   23 Jun 1992 16:09:50   DCODY
  39.  * pas2 update...
  40.  * 
  41.  *    Rev 1.0   15 Jun 1992 09:26:40   BCRANE
  42.  * Initial revision.
  43. */
  44. /*$Logfile:   X:/sccs/pcmapps/playfile.c_v  $*/
  45. /*$Modtimes$*/
  46. /*$Revision:   1.10  $*/
  47. /*$Workfile:   playfile.c  $*/
  48.  
  49.  
  50.     /*\
  51.     |*|----====< PLAYFILE.C >====----
  52.     |*|
  53.     |*| Play the voice file from disk to the PCM hardware
  54.     |*|
  55.     |*| Copyright (c) 1991, Media Vision, Inc. All rights reserved.
  56.     |*|
  57.     \*/
  58.  
  59. #ifndef OEM
  60. #define OEM    0    /* OEM compile flag                    */
  61. #endif
  62. #ifndef PROAS
  63. #define PROAS    0    /* Pro Audio Spectrum compile flag                    */
  64. #endif
  65. #ifndef THUNDER
  66. #define THUNDER 0    /* Thunder Board compile flag                        */
  67. #endif
  68.  
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71. #include <malloc.h>
  72. #include <signal.h>
  73. #include "playtext.h"
  74.  
  75. #if PROAS
  76. #include "play.h"
  77. #include "common.h"
  78. #include "pcmio.h"
  79. #endif
  80.  
  81. #if THUNDER
  82. #include "proto.h"
  83. #include "play.h"
  84. #include "common.h"
  85. #include "pcmio.h"
  86. #include "mvsound.h"
  87. #endif
  88.  
  89.  
  90.     /*\
  91.     |*|----====< Global Variables >====----
  92.     \*/
  93.  
  94.         extern int DMARunning;
  95.  
  96.         long mvGetHWVersion (int);
  97.  
  98.  
  99.     /*\
  100.     |*|----====< Local Variables >====----
  101.     \*/
  102.  
  103.         static FILE *inf;                /* user input file                */
  104.  
  105.         static long SampleRate = 11025L;/* default sample rate            */
  106.         static int    StereoMono = 0;     /* default to mono                */
  107.         static int    Filter       = -1;    /* filter override #            */
  108.         static int    Compression= FALSE; /* compressed data                */
  109.  
  110.         static int    DMAChannel = -1;    /* default to standard DMA        */
  111.         static int    IRQChannel = -1;    /* default to standard IRQ        */
  112.  
  113.         static int    speed = 100;        /* 100 percent                    */
  114.  
  115.         static int    UserStereoMono = -1;/* user's override flag = mono  */
  116.         static long UserSampleRate = -1;/* user's override = 11k        */
  117.         static long DataLength       = -1;/* -1 goes to EOF                */
  118.  
  119.         static int    maxsize    = 16;    /* 16k DMA buffer size            */
  120.         static int    maxdiv       = 4;     /* 4k divisions on the DMA        */
  121.         static int    datasize   = 8;     /* 8 bit or 16 bit pcm            */
  122.         static int    dsoverride = FALSE; /* data size override            */
  123.  
  124. #define ALLOTHERS    0                    /* assume an 8 bit data file    */
  125. #define WAVEFILE    1                    /* wave type of file            */
  126. #define VOCFILE     2                    /* .voc 8 bit pcm file            */
  127.         static int    FileType;            /* type of source file            */
  128.  
  129. #define BUFFLEN     4096
  130.         static char vocbuffer[BUFFLEN]; /* 4k worth of data             */
  131.         static long VOCBlockLength;     /* current block length         */
  132.         static char VOCBlockType;        /* current block type            */
  133.         static char VOCPackType;
  134.  
  135.         int  CommandLine    ( int, char *[] );
  136.         int  DoExit         ( int );
  137.         int  FetchVOCData   ( char * ); /* buffer of PCM data           */
  138.         int  PreProcessFile ( char * );
  139.         int  SetupPlayRate  ( );
  140.         void SetupSound     ( );
  141.  
  142.  
  143.     /*\
  144.     |*|----====< Main >====----
  145.     |*|
  146.     |*| Play the voice file out to the PCM hardware
  147.     |*|
  148.     \*/
  149.  
  150. main(argc,argv)
  151.     int  argc;
  152.     char *argv[];
  153. {
  154. char c;
  155.  
  156.     /* give the opening welcome & checkout the hardware                 */
  157.  
  158.         Welcome();
  159.  
  160.     /* set the runtime switches                                         */
  161.  
  162.         CommandLine (argc,argv);
  163.  
  164.     /* disable the ^C                                                   */
  165.  
  166.         signal (SIGINT,SIG_IGN);
  167.  
  168.     /* need a file name to play, exit if not found                        */
  169.  
  170.         PreProcessFile (argv[1]);
  171.  
  172.         if (OpenPCMBuffering(DMAChannel,IRQChannel,maxsize,maxdiv)) {
  173.             printf (TXT_MSG1);
  174.             DoExit (-1);
  175.         }
  176.  
  177.     /* setup how this file sounds                                        */
  178.  
  179.         SetupSound();
  180.  
  181.     /* Start the DMA & wait till an ESC is typed or data ends           */
  182.  
  183.         printf (TXT_MSG2);
  184.  
  185.         if (FileType <= WAVEFILE) {
  186.  
  187.             /* .WAV & all other files can go out using normal file I/O    */
  188.  
  189.             if (StartFileOutput( inf, DataLength )) {
  190.  
  191.                 while (1) {
  192.  
  193.                     /* if all done, then just break                     */
  194.  
  195.                         if (!ContinueFileOutput())
  196.                             break;
  197.  
  198.                     /* if ESC typed, kill the DMA & exit                */
  199.  
  200.                         if (kbhit()) {
  201.  
  202.                             if ((c = getch()) == 0x1b) {
  203.                                 StopDMAIO();
  204.                                 break;
  205.                             }
  206.                             if (c == ' ') {
  207.                                 PausePCM();
  208.                                 printf (TXT_MSG3);
  209.                                 GetKey();
  210.                                 printf (TXT_MSG4);
  211.                                 ResumePCM();
  212.                             }
  213.                         }
  214.                 }
  215.             }
  216.         }
  217.         else {
  218.  
  219.             /* if there is data available, play it...                    */
  220.  
  221.             if (FetchVOCData(vocbuffer)) {
  222.  
  223.                 /* start the output with the first block of data        */
  224.  
  225.                 if (StartBlockOutput( vocbuffer )) {
  226.  
  227.                     /* fetch the next block of data                     */
  228.  
  229.                     FetchVOCData(vocbuffer);
  230.  
  231.                     while (1) {
  232.  
  233.                         /* if the block can be passed, reload it        */
  234.  
  235.                             if (ContinueBlockOutput(vocbuffer)) {
  236.                                 if (!FetchVOCData(vocbuffer))
  237.                                     break;
  238.                             }
  239.  
  240.                         /* if ESC typed, kill the DMA & exit            */
  241.  
  242.                             if (kbhit()) {
  243.  
  244.                                 if ((c = getch()) == 0x1b) {
  245.                                     StopDMAIO();
  246.                                     DoExit(0);
  247.                                 }
  248.                                 if (c == ' ') {
  249.                                     PausePCM();
  250.                                     printf (TXT_MSG5);
  251.                                     GetKey();
  252.                                     printf (TXT_MSG6);
  253.                                     ResumePCM();
  254.                                 }
  255.                             }
  256.                     }
  257.  
  258.                     /* wait till the DMA finishes                        */
  259.  
  260.                     while (DMARunning) ;
  261.  
  262.                 }
  263.             }
  264.         }
  265.  
  266.     /* exit to DOS                                                        */
  267.  
  268.         DoExit(0);
  269.  
  270. }
  271.  
  272.  
  273.     /*\
  274.     |*|----====< CommandLine >====----
  275.     |*|
  276.     |*| process the command line switches
  277.     |*|
  278.     \*/
  279. int CommandLine(argc,argv)
  280.     int argc;
  281.     char *argv[];
  282. {
  283. char *s;
  284. int n,temp;
  285. long longtemp;
  286.  
  287.     /* exit if no additional parameters                                 */
  288.  
  289.         if (argc < 2) {
  290.             GiveHelps();
  291.             DoExit (-1);
  292.         }
  293.  
  294.         n = 2;
  295.         while (n < argc) {
  296.  
  297.             s = argv[n++];
  298.  
  299.             if (*s == '/') s++;
  300.             if (*s == '-') s++;
  301.  
  302.             switch (*s & 0x5f) {
  303.  
  304. #if PROAS
  305.                 case '1' & 0x5f:
  306.                 case '8' & 0x5f:
  307.                     if (*++s == '6')
  308.                         datasize   = 16;
  309.                     dsoverride = TRUE;
  310.  
  311.                     break;
  312.  
  313.                 case 'F':
  314.                     Filter = *++s - 0x30;
  315.                     if ((Filter > 6) || (Filter < 0))
  316.                         Filter = -1;
  317.                     break;
  318. #endif
  319.  
  320.                 case 'D':
  321.                     temp = *++s - 0x30;
  322.                     if ((temp <= 7) && (temp >= 1)) {
  323.                         if (temp == 4) temp = 0;
  324.                         DMAChannel = temp;
  325.                     }
  326.                     break;
  327.  
  328.                 case 'I':
  329.                     if (sscanf (++s,"%d",&temp) == 1) {
  330.                         if ((1 << temp) & 0x9CBC)
  331.                             IRQChannel = temp;
  332.                     }
  333.                     break;
  334.  
  335.                 case 'M':
  336.                     maxsize = 64;
  337.                     maxdiv    = 16;
  338.                     break;
  339.  
  340.                 case 'R':
  341.                     if (sscanf (++s,"%ld",&longtemp) == 1) {
  342.                         if ((longtemp >4000L) && (longtemp < 88200L))
  343.                             UserSampleRate = longtemp;
  344.                     }
  345.                     break;
  346.  
  347.                 case 'S':
  348.                     s++;
  349.  
  350.                     if (*s == '\0')
  351.                         UserStereoMono = 1;
  352.                     else {
  353.                         if (sscanf (s,"%d",&temp) == 1) {
  354.                             if ((temp >= 0) && ( temp <= 200))
  355.                                 speed = temp;
  356.                         }
  357.                     }
  358.                     break;
  359.  
  360.                 default:
  361.                     break;
  362.             }
  363.         }
  364. }
  365.  
  366.  
  367.     /*\
  368.     |*|----====< DoExit() >====----
  369.     |*|
  370.     |*| Exit to DOS
  371.     |*|
  372.     \*/
  373. int DoExit(cc)
  374.     int cc;
  375. {
  376.         ClosePCMBuffering();
  377.         exit (cc);
  378. }
  379.  
  380.  
  381.     /*\
  382.     |*|----====< GiveHelps() >====----
  383.     |*|
  384.     |*| print text helps & return
  385.     |*|
  386.     \*/
  387. int GiveHelps()
  388. {
  389.  
  390.     /* print & return...                                                */
  391.  
  392. #if PROAS
  393.         printf (TXT_MSG7);
  394.         printf (TXT_MSG8);
  395.         printf (TXT_MSG9);
  396.         printf (TXT_MSG10);
  397.         printf (TXT_MSG11);
  398.         printf (TXT_MSG12);
  399.         printf (TXT_MSG13);
  400.         printf (TXT_MSG14);
  401.         printf (TXT_MSG15);
  402.         printf (TXT_MSG16);
  403.         printf (TXT_MSG17);
  404. #endif
  405.  
  406. #if THUNDER
  407.         printf (TXT_MSG18);
  408.         printf (TXT_MSG19);
  409.         printf (TXT_MSG20);
  410.  #if THUNDER==2
  411.         printf (TXT_MSG21);
  412.         printf (TXT_MSG22);
  413.  #else
  414.         printf (TXT_MSG23);
  415.  #endif
  416.         printf (TXT_MSG24);
  417.         printf (TXT_MSG25);
  418.         printf (TXT_MSG26);
  419. #endif
  420. }
  421.  
  422.  
  423.     /*\
  424.     |*|----====< FetchVOCData >====----
  425.     |*|
  426.     |*| Get a new key
  427.     |*|
  428.     \*/
  429. int FetchVOCData(buff)
  430.     char *buff;
  431. {
  432. int loaded = 0, n;
  433. int looping = TRUE;
  434. int remaining = BUFFLEN;
  435.  
  436.     /* grab the next block of data                                        */
  437.  
  438.         looping = 1;
  439.         while (looping) {
  440.  
  441.             /* process the header                                        */
  442.  
  443.                 switch (VOCBlockType) {
  444.  
  445.                     case TERMINATOR:
  446.  
  447.                         for (;remaining;remaining--)
  448.                             *buff++ = 0x80;
  449.                         remaining = 0;
  450.                         looping = 0;        /* this will knock us out    */
  451.                         break;
  452.  
  453.                     case VOICECONTINUE:
  454.                     case VOICEDATA:
  455.  
  456.                         /* load the data, try to span blocks            */
  457.  
  458.                         if (VOCBlockLength < remaining) {
  459.                             remaining -= VOCBlockLength;
  460.                             n = fread (buff,1,(size_t)VOCBlockLength,inf);
  461.                             loaded += n;
  462.                             buff += n;
  463.                             VOCBlockLength = 0;
  464.                         }
  465.                         else {
  466.                             n = fread(buff,1,remaining,inf);
  467.                             loaded += n;
  468.                             VOCBlockLength -= n;
  469.                             looping = remaining = 0;
  470.                         }
  471.                         break;
  472.  
  473.                     case SILENCE:
  474.  
  475.                         /* load the data, try to span blocks            */
  476.  
  477.                         if (VOCBlockLength < remaining) {
  478.                             remaining -= VOCBlockLength;
  479.                             loaded += VOCBlockLength;
  480.                             for (;VOCBlockLength;VOCBlockLength--)
  481.                                 *buff++ = 0x80;
  482.                         }
  483.                         else {
  484.                             loaded = remaining;
  485.                             VOCBlockLength -= remaining;
  486.                             for (;remaining;remaining--)
  487.                                 *buff++ = 0x80;
  488.                             looping = remaining = 0;
  489.                         }
  490.                         break;
  491.  
  492.                     case MARKER:
  493.                     case REPEAT:
  494.                     case ENDREPEAT:
  495.                     case ASCIITEXT:
  496.  
  497.                         /* all the rest of the header were eaten by the     */
  498.                         /* "GetNextBlock" routine. We will continue till we */
  499.                         /* find data, or the terminating record             */
  500.  
  501.                     default:
  502.                         break;
  503.                 }
  504.  
  505.                 /* span blocks, but exit on EOF                             */
  506.  
  507.                 if (remaining) {
  508.                     if (!GetNextBlock()) {
  509.                         for (;remaining;remaining--)
  510.                             *buff++ = 0x80;
  511.                         looping = FALSE;
  512.                     }
  513.                 }
  514.         }
  515.  
  516.     /* return with data data block                                            */
  517.  
  518.         return(loaded);
  519. }
  520.  
  521.  
  522.     /*\
  523.     |*|----====< GetKey() >====----
  524.     |*|
  525.     |*| Get a new key
  526.     |*|
  527.     \*/
  528. int GetKey()
  529. {
  530. char c;
  531.  
  532.     while (kbhit()) getch();
  533.  
  534.     while (!kbhit()) ;
  535.     if (getch() == 0) getch();
  536.  
  537. }
  538.  
  539.  
  540.     /*\
  541.     |*|----====< GetNextBlock() >====----
  542.     |*|
  543.     |*| Process the header to the next block, & return TRUE if data is
  544.     |*| pointed to.
  545.     |*|
  546.     \*/
  547. int GetNextBlock()
  548. {
  549. int looping = TRUE;
  550. long l;
  551.  
  552.     /* get the record type & process to get the sample rate             */
  553.  
  554.         VOCBlockLength = 0;             /* we must end up with data!    */
  555.         while (looping) {
  556.  
  557.             switch (VOCBlockType = fgetc(inf)) {
  558.  
  559.                 case TERMINATOR:
  560.                     return(0);            /* if at the end, just exit     */
  561.  
  562.                 case SILENCE:
  563.                     fgetc(inf);fgetc(inf);fgetc(inf);
  564.                     VOCBlockLength  = fgetc(inf) & 0xff;
  565.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  566.                     SetupPlayRate(fgetc(inf) & 0xff);
  567.                     VOCBlockLength -= 3;    /* 3 less for header data    */
  568.                     looping = FALSE;
  569.                     break;
  570.  
  571.                 case VOICEDATA:
  572.                     VOCBlockLength    = fgetc(inf) & 0xff;
  573.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  574.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 16;
  575.                     SetupPlayRate(fgetc(inf) & 0xff);
  576.  
  577.                     /* determine mono/stereo                            */
  578.  
  579.                     StereoMono = 0;
  580.                     if (((VOCPackType = fgetc(inf)) & 0xff) == 5) {
  581.                         StereoMono = 1;
  582.                         VOCPackType = 0;
  583.                     }
  584. #if THUNDER
  585.                     /* determine compression                            */
  586.  
  587.                     if (VOCPackType <= 3)    /* types 0 - 3                */
  588.                         Compression = VOCPackType;
  589. #endif
  590.                     VOCBlockLength -= 2;    /* 2 less for header data   */
  591.                     looping = FALSE;
  592.                     break;
  593.  
  594.                 case ASCIITEXT:
  595.                     l  = fgetc(inf) & 0xff;
  596.                     l += ((long)(fgetc(inf) & 0xff)) << 8;
  597.                     l += ((long)(fgetc(inf) & 0xff)) << 16;
  598.                     for (;l;l--)
  599.                         fgetc(inf);
  600.                     break;
  601.  
  602.                 case MARKER:
  603.                 case REPEAT:
  604.                     fgetc(inf);fgetc(inf);
  605.                 case ENDREPEAT:
  606.                     fgetc(inf);fgetc(inf);fgetc(inf);
  607.                     break;
  608.  
  609.                 default:
  610.                     printf (TXT_MSG27);
  611.                     DoExit(-1);
  612.                     break;
  613.  
  614.             }
  615.         }
  616.  
  617.     /* we leave the file pointing to the first data byte                */
  618.  
  619.         return(1);
  620. }
  621.  
  622.     /*\
  623.     |*|----====< PreProcessFile >====----
  624.     |*|
  625.     |*| Fill the play buffer with the contents of the disk file
  626.     |*|
  627.     \*/
  628. int PreProcessFile (fn)
  629.     char *fn;
  630. {
  631. char buff[100];
  632. int n,looping;
  633. long psize,l;
  634. char *p,*b;
  635. long* ptr;
  636. FILE *wf;
  637.  
  638.     /* attempt to open the users disk file                                */
  639.  
  640.         if ((inf = fopen(fn,"rb")) == 0) {
  641.  
  642.             strcpy (buff,fn);
  643.             strcat (buff,".WAV");
  644.             if ((inf = fopen(buff,"rb")) == 0) {
  645.  
  646.                 strcpy (buff,fn);
  647.                 strcat (buff,".VOC");
  648.                 if ((inf = fopen(buff,"rb")) == 0) {
  649.  
  650.                     printf (TXT_MSG28,fn);
  651.                     DoExit (-1);
  652.                 }
  653.             }
  654.         }
  655.  
  656.     /* get the 1st 2 characters in the file                             */
  657.  
  658.         n = fgetc(inf) & 0xff;
  659.         n = n + ((fgetc(inf) & 0xff) << 8);
  660.  
  661.         fseek (inf,0L,SEEK_SET); /* rewind to the start                 */
  662.  
  663.     /* special case a .WAV file                                         */
  664.  
  665.         if (n == 0x4952) {
  666.              ProcessWAVFile();
  667.              return(0);
  668.         }
  669.  
  670.     /* special case anything else than a .VOC file                        */
  671.  
  672.         if (n != 0x7243) {        /* if NE to Creative..., then it's PCM  */
  673.              ProcessPCMFile();
  674.              return(0);
  675.         }
  676.  
  677.     /* .VOC type of source file                                         */
  678.  
  679.         FileType = VOCFILE;
  680.  
  681.     /* get the header of the voice file                                 */
  682.  
  683.         b = &buff[0];
  684.         fseek(inf,0L,SEEK_SET);         /* move to the first byte        */
  685.         for (n=0;n<(sizeof (VOCHDR));n++)
  686.             *b++ = fgetc(inf);
  687.  
  688.         if (feof(inf)) {
  689.             printf (TXT_MSG29);
  690.             DoExit (-1);
  691.         }
  692.  
  693.     /* Make sure it's a legit file                                      */
  694.  
  695.         if (strncmp (buff,"Creative Voice File",0x13) != 0) {
  696.             printf (TXT_MSG30);
  697.             DoExit (-1);
  698.         }
  699.  
  700.         p = &buff[0x14];                /* get a pointer to the offset    */
  701.  
  702.         psize = LONG(*p) & 0xffff;        /* get the 16 bit word            */
  703.  
  704.         fseek(inf,psize,SEEK_SET);        /* move to the first byte        */
  705.  
  706.         if (!GetNextBlock())            /* process the next header        */
  707.             DoExit(0);
  708.  
  709. }
  710.  
  711.  
  712.     /*\
  713.     |*|----====< ProcessWAVFile >====----
  714.     |*|
  715.     |*| load the header from our WAV file format
  716.     |*|
  717.     \*/
  718. int ProcessWAVFile(f)
  719. {
  720. int n;
  721. char *b,c;
  722. WaveInfo whd;
  723. DataHeader dhd;
  724.  
  725.     /* We are a WAVE file                                                */
  726.  
  727.         FileType = WAVEFILE;            /* type of source file          */
  728.  
  729.     /* eat the RIFF portion of the header                                */
  730.  
  731.         c = fgetc(inf);
  732.  
  733.         if (c == 'R') {
  734.             for (n=7;n;n--)
  735.                 fgetc(inf);
  736.             c = fgetc(inf);
  737.         }
  738.  
  739.     /* pas up the wave block header name                                */
  740.  
  741.         if (c != 'W') {
  742.             printf (TXT_MSG31);
  743.             DoExit(-1);
  744.         }
  745.         fgetc(inf); fgetc(inf); fgetc(inf);     /* move past the data    */
  746.  
  747.     /* pass up the format section name                                    */
  748.  
  749.         c = fgetc(inf);
  750.         if (c != 'f') {
  751.             printf (TXT_MSG32);
  752.             DoExit(-1);
  753.         }
  754.         for (n=7;n;n--)
  755.             fgetc(inf);                         /* move past the data    */
  756.  
  757.     /* load the actual header data                                        */
  758.  
  759.         b = (char *) &whd;
  760.         for (n=0;n<sizeof (WaveInfo);n++)
  761.             *b++ = fgetc(inf);
  762.  
  763.     /* grab the sample rate                                             */
  764.  
  765.         StereoMono = whd.nChannels - 1;
  766.         SampleRate = whd.nSamplesPerSec;
  767.  
  768.     /* setup the data size only if no override has been requested        */
  769.  
  770.         if (!dsoverride)
  771.             datasize   = whd.nBitsPerSample;
  772.  
  773.     /* go to the data section and get the data length                    */
  774.  
  775.         b = (char *) &dhd;
  776.         for (n=0;n<sizeof(DataHeader);n++)
  777.             *b++ = fgetc(inf);                    /* move past the data    */
  778.  
  779.         if (dhd.name[0] != 'd') {
  780.             printf (TXT_MSG33);
  781.             DoExit(-1);
  782.         }
  783.  
  784.         DataLength = dhd.length;
  785.  
  786. }
  787.  
  788.  
  789.     /*\
  790.     |*|----====< ProcessPCMFile >====----
  791.     |*|
  792.     |*| load the header from our PCM file format
  793.     |*|
  794.     \*/
  795. int ProcessPCMFile()
  796. {
  797. int n;
  798. char *b;
  799.  
  800.     /* we are some unknown data type                                    */
  801.  
  802.         FileType = ALLOTHERS;            /* type of source file            */
  803.  
  804.     /* ask for the sample rate                                          */
  805.  
  806.         if (UserSampleRate != -1) {
  807.             SampleRate = UserSampleRate;
  808.  
  809.             if (UserStereoMono == -1)
  810.                 UserStereoMono = 0;
  811.  
  812.             StereoMono = UserStereoMono;
  813.         }
  814.         else {
  815.  
  816.             SampleRate = 11025L;
  817.             printf (TXT_MSG34);
  818.             while (1) {
  819.                 if (scanf ("%ld",&SampleRate) == 1)
  820.                     break;
  821.             }
  822.  
  823.             printf (TXT_MSG35);
  824.             while (1) {
  825.                 if (scanf ("%d",&StereoMono) == 1) {
  826.                     StereoMono--;    /* make it zero based                */
  827.                     break;
  828.                 }
  829.             }
  830.         }
  831.  
  832.         if ((StereoMono < 0) || (StereoMono > 1))
  833.             StereoMono = 0;
  834. }
  835.  
  836.  
  837.     /*\
  838.     |*|----====< SetupPlayRate >====----
  839.     |*|
  840.     |*| Setup the playing rate of the interrupt routine.
  841.     |*|
  842.     \*/
  843. int SetupPlayRate(n)
  844.     int n;
  845. {
  846.  
  847.     /* we will use a default rate                                        */
  848.  
  849.         SampleRate = 11025L;
  850.  
  851.     /* search for the real rate                                         */
  852.  
  853.         while (1) {
  854.  
  855.             if (n <= 6) {
  856.                 SampleRate = 4000L;         /* 4000 kh sampling         */
  857.                 break;
  858.             }
  859.  
  860.             if (n <= 56) {
  861.                 SampleRate = 5000L;         /* 5000 kh sampling         */
  862.                 break;
  863.             }
  864.  
  865.             if (n <= 90) {
  866.                 SampleRate = 6000L;         /* 6000 kh sampling         */
  867.                 break;
  868.             }
  869.  
  870.             if (n <= 114) {
  871.                 SampleRate = 7000L;         /* 7000 kh sampling         */
  872.                 break;
  873.             }
  874.  
  875.             if (n <= 131) {
  876.                 SampleRate = 8000L;         /* 8000 kh sampling         */
  877.                 break;
  878.             }
  879.  
  880.             if (n <= 145) {
  881.                 SampleRate = 9000L;         /* 9000 kh sampling         */
  882.                 break;
  883.             }
  884.  
  885.             if (n <= 156) {
  886.                 SampleRate = 10000L;        /* 10000 kh sampling        */
  887.                 break;
  888.             }
  889.  
  890.             if (n <= 166) {
  891.                 SampleRate = 11000L;        /* 11000 kh sampling        */
  892.                 break;
  893.             }
  894.  
  895.             if (n <= 173) {
  896.                 SampleRate = 12000L;        /* 11000 kh sampling        */
  897.                 break;
  898.             }
  899.  
  900.             if (n <= 180) {
  901.                 SampleRate = 13000L;        /* 11000 kh sampling        */
  902.                 break;
  903.             }
  904.  
  905.             if (n <= 185) {
  906.                 SampleRate = 14000L;        /* 11000 kh sampling        */
  907.                 break;
  908.             }
  909.  
  910.             if (n <= 190) {
  911.                 SampleRate = 15000L;        /* 11000 kh sampling        */
  912.                 break;
  913.             }
  914.  
  915.             if (n <= 194) {
  916.                 SampleRate = 16000L;        /* 11000 kh sampling        */
  917.                 break;
  918.             }
  919.  
  920.             if (n <= 198) {
  921.                 SampleRate = 17000L;        /* 11000 kh sampling        */
  922.                 break;
  923.             }
  924.  
  925.             if (n <= 201) {
  926.                 SampleRate = 18000L;        /* 11000 kh sampling        */
  927.                 break;
  928.             }
  929.  
  930.             if (n <= 204) {
  931.                 SampleRate = 19000L;        /* 11000 kh sampling        */
  932.                 break;
  933.             }
  934.  
  935.             if (n <= 206) {
  936.                 SampleRate = 20000L;        /* 11000 kh sampling        */
  937.                 break;
  938.             }
  939.  
  940.             if (n <= 209) {
  941.                 SampleRate = 21000L;        /* 11000 kh sampling        */
  942.                 break;
  943.             }
  944.  
  945.             if (n <= 211) {
  946.                 SampleRate = 22000L;        /* 11000 kh sampling        */
  947.                 break;
  948.             }
  949.  
  950.             if (n <= 215) {
  951.                 SampleRate = 23000L;        /* 11000 kh sampling        */
  952.                 break;
  953.             }
  954.  
  955.             /* if unknown value, bomb out...                            */
  956.  
  957.                 printf (TXT_MSG36);
  958.                 DoExit(0);
  959.  
  960.         }
  961. }
  962.  
  963.  
  964.     /*\
  965.     |*|----====< SetupSound() >====----
  966.     |*|
  967.     |*| Setup the sample rate, stereo/mono.
  968.     |*|
  969.     \*/
  970. void SetupSound()
  971. {
  972.  
  973.     /* if the user wants it different...                                */
  974.  
  975.         if (UserSampleRate != -1)
  976.             SampleRate = UserSampleRate;
  977.  
  978.         if (UserStereoMono != -1)
  979.             StereoMono = UserStereoMono;
  980.  
  981.     /* speed is the user's %. from 0 to 200 %                           */
  982.  
  983.         SampleRate = ((SampleRate * speed) + 50) / 100;
  984.  
  985. #if PROAS
  986.         ChooseFilter( SampleRate, Filter );
  987. #endif
  988.  
  989.         PCMState (SampleRate, StereoMono, Compression, datasize );
  990. }
  991.  
  992.  
  993.     /*\
  994.     |*|----====< Welcome >====----
  995.     |*|
  996.     |*| Print the logo & check for the appropriate hardware
  997.     |*|
  998.     \*/
  999. Welcome()
  1000. {
  1001. long ver;
  1002.  
  1003.     /* give the normal stuff...                                         */
  1004.  
  1005. #if OEM
  1006.  
  1007.  #if PROAS
  1008.         printf (TXT_MSG37);
  1009.  #endif
  1010.  
  1011.  #if THUNDER
  1012.         printf (TXT_MSG38);
  1013.  #endif
  1014.  
  1015.         {
  1016.                 static char    zsCopyright[] = "Copyright (c) 1991,1992 Media Vision, Inc. All Rights Reserved\n\n";
  1017.         }
  1018.  
  1019. #else
  1020.  
  1021.  #if PROAS
  1022.         printf (TXT_MSG39);
  1023.  #endif
  1024.  
  1025.  #if THUNDER
  1026.   #if THUNDER==2
  1027.         printf (TXT_MSG40);
  1028.   #else
  1029.         printf (TXT_MSG41);
  1030.   #endif
  1031.  #endif
  1032.  
  1033.         printf (TXT_MSG42);
  1034.  
  1035. #endif  //OEM
  1036.  
  1037.     /* check for the hardware                                            */
  1038.  
  1039. #if PROAS
  1040.         ver = mvGetHWVersion(USE_ACTIVE_ADDR); /* get the version               */
  1041.         if (ver == -1) {
  1042.  #if OEM
  1043.             printf (TXT_MSG43);
  1044.  #else     //OEM
  1045.             printf (TXT_MSG44);
  1046.  #endif  //OEM
  1047.             GiveHelps();
  1048.             exit(-1);
  1049.         }
  1050. #endif
  1051.  
  1052. #if THUNDER
  1053.         ver = mvGetHWVersion(0);        /* get the version, or something.. */
  1054.         if ((ver < 0) || ((ver & 0xffff0000) != 0x00010000)) {
  1055.  #if OEM
  1056.             printf (TXT_MSG45);
  1057.  #else     //OEM
  1058.   #if THUNDER==2
  1059.             printf (TXT_MSG46);
  1060.   #else
  1061.             printf (TXT_MSG47);
  1062.   #endif
  1063.  #endif
  1064.             GiveHelps();
  1065.             exit(-1);
  1066.         }
  1067.  
  1068. #endif  //THUNDER
  1069. }
  1070.  
  1071.     /*\
  1072.     |*| end of PLAYFILE.C
  1073.     \*/
  1074.  
  1075.  
  1076.